﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Linq
{
    class TestLinq
    {
        static void Main(string[] args)
        {
            List<Student> students = new List<Student>();
            students.Add(new Student("Pesho", "Pesho", 1234406, "123-465-48", "sads@as.fv", new List<int> { 4, 4, 5 }, 2));
            students.Add(new Student("Gosho", "Pesho", 1234064, "123-465-48", "sads@as.fv", new List<int> { 4, 4, 5 }, 1));
            students.Add(new Student("Pesho", "Gosho", 1234404, "123-465-48", "sads@as.fv", new List<int> { 2, 2, 2 }, 2));
            students.Add(new Student("Chicho", "Pesho", 12340444, "024-465-48", "sads@as.fv", new List<int> { 2, 2, 5, }, 3));
            students.Add(new Student("Dqdo", "Mraz", 1234450, "123-465-48", "sads@abv.bg", new List<int> { 4, 4, 5 }, 1));
            students.Add(new Student("Aleksandur", "Beninski", 12340544, "123-465-48", "sads@abv.bg", new List<int> { 6, 4, 5 }, 2));

            List<Group> groups = new List<Group>();
            groups.Add(new Group(1,"Mathematics"));
            groups.Add(new Group(2,"Phisics"));

            //var selected =
            //    from student in students
            //    where student.Group == 2
            //    orderby student.FirstName
            //    select student;

            //var selected = students.Where(st => st.Group == 2).OrderBy(st=>st.FirstName);


            //var selected =
            //    from student in students
            //    where student.Email.EndsWith("abv.bg")
            //    orderby student.FirstName
            //    select student;

            //var selected = students.Where(st => st.Email.EndsWith("abv.bg"));

            //Regex pattern = new Regex(@"(02)+\w*\W*");

            //var selected = students.Where(st => pattern.IsMatch(st.Tel));

            //var selected =
            //    from student in students
            //    where student.Marks.Contains(6)
            //    orderby student.FirstName
            //    select new {a=student.FirstName+" "+ student.LastName, b=student.Marks };

            //var selected = students.Where(st => st.Marks.Count(s => s == 2) == 2).Select
            //    (st => new { a = st.FirstName + " " + st.LastName, b = st.Marks });

            //var selected = students.Where(st => st.Fn.ToString().Substring(4, 2) == "06");

            //foreach (var item in selected)
            //{
            //    Console.WriteLine(item.a + ": ");
            //    foreach (var mark in item.b)
            //    {
            //        Console.WriteLine(mark);
            //    }
            //}

            //var selected =
            //    from student in students
            //    join gr in groups on student.Group equals gr.GroupNumer
            //    where gr.DepartmentName == "Mathematics"
            //    select student;


            foreach (var item in selected)
            {
                Console.WriteLine(item.FirstName + " " +item.LastName );
            }
        }
    }
}
